home *** CD-ROM | disk | FTP | other *** search
- /*=====================================================================
- File: IndentedWriter.cool
-
- Summary: Utility class used to provide basic text out services that
- can be indented.
-
- Classes: FindType
- Indented Writer
-
- Origin: COM+ 2.0 Samples Team
-
- ---------------------------------------------------------------------
- This file is part of the Microsoft COM+ 2.0 SDK Code Samples.
-
- Copyright (C) 1999 Microsoft Corporation. All rights reserved.
-
- This source code is intended only as a supplement to Microsoft
- Development Tools and/or on-line documentation. See these other
- materials for detailed information regarding Microsoft code samples.
-
- THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
- KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
- PARTICULAR PURPOSE.
- =====================================================================*/
- namespace Microsoft.Samples.Reflection
- {
- using System;
- using System.IO;
- using System.Text;
-
- /*=====================================================================
- Class: Indented Writer
-
- Summary: Utility class that performs basic text output operations
- that can be indented via "push" and "pop". The text writer
- used to write information out can be changed by setting the
- appropriate property. The default text writer is
- System.Console.Out.
-
- =====================================================================*/
- public class IndentedWriter
- {
- private TextWriter myTextWriter = Console.Out;
- private bool myPrintFlag = true;
- private int myIndent = 0;
-
-
- /*=====================================================================
- [Public] Property: Print
-
- Type: Boolean
-
- Description: Controls whether printing is performed or not. This can
- be useful for clients that require a "verbose" writer
- that only displays information when the verbose mode is
- set.
- =====================================================================*/
- public bool Print
- {
- get { return myPrintFlag; }
- set { myPrintFlag = value; }
- }
-
- /*=====================================================================
- [Public] Property: TextWriter
-
- Type: TextWriter
-
- Description: Sets the TextWriter to use when writing strings out.
- =====================================================================*/
- public TextWriter TextWriter
- {
- get { return myTextWriter; }
- set { myTextWriter = value; }
- }
-
- /*=====================================================================
- [Public] Method: PushIndent
-
- Description: Pushs the current indent.
- =====================================================================*/
- public void PushIndent()
- {
- myIndent += 2;
- }
-
- /*=====================================================================
- [Public] Method: PopIndent
-
- Description: Pushs the current indent.
- =====================================================================*/
- public void PopIndent()
- {
- if (myIndent > 0)
- {
- myIndent -= 2;
- }
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Description: Writes out an empty line.
- =====================================================================*/
- public void WriteLine()
- {
- WriteLine("");
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Parameter(s)
- format The string format to use
- arg0 The first argument for the string format.
-
- Description: Writes a formatted string.
- =====================================================================*/
- public void WriteLine(String format, Object arg0)
- {
- WriteLine( String.Format(format, arg0) );
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Parameter(s)
- format The string format to use
- arg0 The first argument for the string format.
- arg1 The second argument for the string format.
-
- Description: Writes a formatted string.
- =====================================================================*/
- public void WriteLine(String format, Object arg0, Object arg1)
- {
- WriteLine( String.Format(format, arg0, arg1) );
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Parameter(s)
- format The string format to use
- arg0 The first argument for the string format.
- arg1 The second argument for the string format.
- arg2 The third argument for the string format.
-
- Description: Writes a formatted string.
- =====================================================================*/
- public void WriteLine(String format, Object arg0, Object arg1, Object arg2)
- {
- WriteLine( String.Format(format, arg0, arg1, arg2) );
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Parameter(s)
- format The string format to use
- arg[] An array of arguments to be used in the string format.
-
- Description: Writes a formatted string.
- =====================================================================*/
- public void WriteLine(String format, Object[] arg)
- {
- WriteLine( String.Format(format, arg) );
- }
-
- /*=====================================================================
- [Public] Method: WriteLine
-
- Parameter(s)
- message The string to write out.
-
- Description: Writes out a string (indented it as required)
- =====================================================================*/
- public void WriteLine(string message)
- {
- if (myPrintFlag)
- {
- StringBuilder sb = new StringBuilder();
-
- for (int i = 0; i < myIndent; i++)
- {
- sb.Append(' ');
- }
-
- myTextWriter.WriteLine( sb.ToString() + message );
- }
- }
- }
- }